<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            const p1 = new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(1111);
                }, 1000);
            });
            const p2 = new Promise((resolve, reject) => {
                setTimeout(() => {
                    reject(222);
                }, 2000);
            });
            const p3 = new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(3333);
                }, 3000);
            });
            // 在全部的promise拿到 结果 resolve后，才会返回数组
            // 如果有 promise 执行错误，就会中断后面的promise,且不会打印出结果
            Promise.all([p1, p2, p3, 'aaaa'])
                .then((res) => {
                    console.log('then', res); // [1111,2222,3333,aaaa]
                })
                .catch((err) => {
                    console.log(err);
                });
        </script>
    </body>
</html>
